package com.wu.controller;

import com.wu.mapper.UserMapper;
import com.wu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;


    @GetMapping("/findall/{page}/{limit}")
    public List<User> findAll(@PathVariable("page") int page,@PathVariable("limit") int limit){
        return userMapper.findAll(page, limit);
    }

    @GetMapping("/findById/{id}")
    public User findById(@PathVariable("id")long id){
        return userMapper.findById(id);
    }

    @GetMapping("/count")
    public int count(){
        return userMapper.count();
    }

    @PostMapping("/save")
    public void save(@RequestBody User user){
        userMapper.save(user);
    }

    @PutMapping("/update")
    public void update(@RequestBody User user){
        userMapper.update(user);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") long id){
        userMapper.deleteById(id);
    }

}
